package com.gemme.gemme.view;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gemme.gemme.R;
import com.gemme.gemme.home.ProductListActivity;

public class ProductChildView extends RelativeLayout {
    private Context context;
    public ProductChildView(Context context) {
        this(context,null);
    }

    public ProductChildView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ProductChildView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    ImageView picture1;
    ImageView picture2;
    TextView name1;
    TextView name2;
    RelativeLayout rl1;
    RelativeLayout rl2;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.product_child_view,this);

        picture1 = findViewById(R.id.picture1);
        picture2 = findViewById(R.id.picture2);
        name1 = findViewById(R.id.name1);
        name2 = findViewById(R.id.name2);
        rl1 = findViewById(R.id.rl1);
        rl2 = findViewById(R.id.rl2);
    }


    public ProductChildView setPicture1(String url){
        if(TextUtils.isEmpty(url))
            return this;
        Glide.with(context).load(url).into(picture1);
        return this;
    }

    public ProductChildView setName1(String nameStr){
        name1.setText(nameStr);
        return this;
    }
     public ProductChildView setPicture2(String url){
        if(TextUtils.isEmpty(url))
            return this;
        Glide.with(context).load(url).into(picture2);
         rl2.setVisibility(VISIBLE);
        return this;
    }

     public ProductChildView setName2(String nameStr){
        name2.setText(nameStr);
         rl2.setVisibility(VISIBLE);
        return this;
      }

    public ProductChildView setProductId1(String id){
        rl1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), ProductListActivity.class);
                intent.putExtra("twoCategoryId",id);
                context.startActivity(intent);
            }
        });

        return this;
    }

    public ProductChildView setProductId2(String id){
        rl2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), ProductListActivity.class);
                intent.putExtra("twoCategoryId",id);
                context.startActivity(intent);
            }
        });

        return this;
    }


}
